package com.shoulder.boot.demo.utils;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shoulder.boot.demo.dto.DemoQueryDTO;
import com.shoulder.boot.demo.entity.Demo;
import com.shoulder.boot.demo.vo.DemoVo;
import com.shoulder.mybatis.utils.PageUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;

public class DemoUtils implements PageUtils<Demo, DemoVo> {

    public static DemoUtils buildUtils() {
        return new DemoUtils();
    }

    @Override
    public DemoVo toVo(Demo entity) {
        DemoVo vo = new DemoVo();
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }
    public static LambdaQueryWrapper<Demo> buildQueryWrapper(DemoQueryDTO queryDTO) {
        LambdaQueryWrapper<Demo> queryWrapper = new LambdaQueryWrapper<Demo>().orderByDesc(Demo::getCreateTime);
        queryWrapper.like(!ObjectUtils.isEmpty(queryDTO.getName()), Demo::getName, queryDTO.getName());
        queryWrapper.eq(!ObjectUtils.isEmpty(queryDTO.getUserId()), Demo::getUserId, queryDTO.getUserId());
        queryWrapper.eq(!ObjectUtils.isEmpty(queryDTO.getDeptId()), Demo::getDeptId, queryDTO.getDeptId());
        queryWrapper.eq(!ObjectUtils.isEmpty(queryDTO.getTenantId()), Demo::getTenantId, queryDTO.getTenantId());
        return queryWrapper;
    }
}